/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxValue = function (grid) {
    let row = grid.length
    let col = grid[0].length
    let dp = new Array(row + 1).fill(0)
    for (let i = 0; i < row + 1; i++) {
        dp[i] = new Array(col + 1).fill(0)
    }
    for (let i = 1; i < row + 1; i++) {
        for (let j = 1; j < col + 1; j++) {
            dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + grid[i - 1][j - 1]
        }
    }
    return dp[row][col]
};
console.log(maxValue([
    [1, 3, 1],
    [1, 5, 1],
    [4, 2, 1]
]))